package com.zhanglj.gis.utils;

import java.util.List;

/**
 *
 * @author asdf
 * @date 2021年3月16日 下午3:21:43
 */
public class TileUtils {
	/**
	 * 将十进制经纬度转换为DMS字符串表达，秒保留4位精度
	 * @param dd
	 * @return
	 */
	private String DecimalDgreeToDMS(double dd) {
		int degrees = (int) dd;
		double minutes = (dd - degrees) * 60;
		double seconds = ((minutes - (int) minutes) * 60);

		return String.format("%d°%d'%d\"", Math.abs(degrees), Math.abs((int) minutes), Math.round(Math.abs(seconds)));
	}
	/**
	 * 将DMS字符串转换为十进制经纬度，保留6位精度
	 * @param dms
	 * @return
	 */
	private double DMSToDecimalDgree(String dms) {
		String[] degrees_split=dms.split("°");
		double degrees=Double.parseDouble(degrees_split[0].trim());
		String[] minute_split=degrees_split[1].split("\'");
		double minutes=Double.parseDouble(minute_split[0].trim())/60;
		//String str=minute_split[1].substring(0, minute_split[1].indexOf("\""));
		double seconds=Double.parseDouble(minute_split[1].substring(0, minute_split[1].indexOf("\"")).trim())/3600;
		return Math.round((degrees+minutes+seconds)*1000000.0)/1000000.0;
		
	}
	//public String 

	public static void main(String[] args) {

		/*String str = "119°6'40\"";
		System.out.println(str.split("°")[3]);*/

		TileUtils util = new TileUtils();
		System.out.println(util.DecimalDgreeToDMS(119.999999));
		System.out.println(util.DMSToDecimalDgree("119°59'60\""));
	}

}
